//package test_grpc
//
//import io.grpc.*
//import io.grpc.stub.StreamObserver
//import com.google.protobuf.*
//
//// 服务端实现
//class BService : BindableService {
//    override fun bindService(): ServerServiceDefinition {
//        return ServerServiceDefinition.builder("grpc.BService")
//            .addMethod(
//                MethodDescriptor.newBuilder<DynamicMessage, DynamicMessage>()
//                    .setType(MethodDescriptor.MethodType.UNARY)
//                    .setFullMethodName(MethodDescriptor.generateFullMethodName("grpc.BService", "SayHello"))
//                    .setRequestMarshaller(ProtoUtils.marshaller(DynamicMessage.getDefaultInstance(DemoSchema.descriptor)))
//                    .setResponseMarshaller(ProtoUtils.marshaller(DynamicMessage.getDefaultInstance(DemoSchema.descriptor)))
//                    .build(),
//                object : ServerCalls.UnaryMethod<DynamicMessage, DynamicMessage> {
//                    override fun invoke(request: DynamicMessage, responseObserver: StreamObserver<DynamicMessage>) {
//                        val msg = request.getField(DemoSchema.descriptor.findFieldByName("msg")) as String
//                        val resp = DynamicMessage.newBuilder(DemoSchema.descriptor)
//                            .setField(DemoSchema.descriptor.findFieldByName("msg"), "BService 收到: $msg")
//                            .build()
//                        responseObserver.onNext(resp)
//                        responseObserver.onCompleted()
//                    }
//                }
//            )
//            .build()
//    }
//}
//
//// 客户端调用
//object BClient {
//    fun sayHello(channel: ManagedChannel, msg: String): String {
//        val method = MethodDescriptor.newBuilder<DynamicMessage, DynamicMessage>()
//            .setType(MethodDescriptor.MethodType.UNARY)
//            .setFullMethodName(MethodDescriptor.generateFullMethodName("grpc.BService", "SayHello"))
//            .setRequestMarshaller(ProtoUtils.marshaller(DynamicMessage.getDefaultInstance(DemoSchema.descriptor)))
//            .setResponseMarshaller(ProtoUtils.marshaller(DynamicMessage.getDefaultInstance(DemoSchema.descriptor)))
//            .build()
//        val stub = ClientCalls.blockingUnaryCall<DynamicMessage, DynamicMessage>(
//            channel, method, CallOptions.DEFAULT,
//            DynamicMessage.newBuilder(DemoSchema.descriptor).setField(DemoSchema.descriptor.findFieldByName("msg"), msg).build()
//        )
//        return stub.getField(DemoSchema.descriptor.findFieldByName("msg")) as String
//    }
//}